using System.Collections.Generic;
using System.Text;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	internal class OracleLpDatetimeExpression : OracleLpExpression
	{
		protected OracleLpExpression m_vDatetime;

		protected OracleLpDatetimeExpressionType m_vDatetimeExpessionType;

		protected OracleLpTimeZoneExpression m_vTimeZone;

		public OracleLpExpression Datetime
		{
			get
			{
				return m_vDatetime;
			}
			set
			{
				m_vDatetime = value;
			}
		}

		public OracleLpDatetimeExpressionType DatetimeExpessionType
		{
			get
			{
				return m_vDatetimeExpessionType;
			}
			set
			{
				if (value != OracleLpDatetimeExpressionType.TIME_ZONE)
				{
					m_vTimeZone = null;
				}
				m_vDatetimeExpessionType = value;
			}
		}

		public OracleLpTimeZoneExpression TimeZone
		{
			get
			{
				return m_vTimeZone;
			}
			set
			{
				m_vTimeZone = value;
			}
		}

		public OracleLpDatetimeExpression(OracleLpStatementElement parent)
			: base(parent)
		{
			m_vExpressionType = OracleLpExpressionType.DATETIME_EXPRESSION;
		}

		public override void EvaluateDatatype()
		{
		}

		public override IList<OracleLpExpression> GetAllTerminalExpressions()
		{
			if (m_vAllTerminalExpressions == null)
			{
				m_vAllTerminalExpressions = new List<OracleLpExpression>();
				m_vAllTerminalExpressions.Add(m_vDatetime);
				if (m_vTimeZone != null)
				{
					m_vAllTerminalExpressions.Add(m_vTimeZone);
				}
			}
			return m_vAllTerminalExpressions;
		}

		internal override void ToString(StringBuilder sb)
		{
			base.ToString(sb);
			sb.Append("  Datetime expression: ");
			m_vDatetime.ToString(sb);
			sb.Append("  Type: ");
			switch (m_vDatetimeExpessionType)
			{
			case OracleLpDatetimeExpressionType.LOCAL:
				sb.Append("LOCAL");
				break;
			case OracleLpDatetimeExpressionType.TIME_ZONE:
				sb.Append("TIME ZONE ");
				m_vTimeZone.ToString(sb);
				break;
			}
		}
	}
}
